<template>
  <div class="p-20">
    <routeDetail :data-list="dataList" />
  </div>
</template>
<script>
import routeData from "./data/route.js";
import { nodeCategory } from "@/enums/DevEnum"; //设备枚举
import routeDetail from "@/components/route-detail";
export default {
  components: {
    routeDetail,
  },
  data() {
    return {
      nodeCategory,
      dataList: [],
    };
  },
  methods: {
    categoryByRegionId() {
      this.dataList = [];
      let formList = [];
      let categoryId = 0; //使用数字区分不同的机房
      let tempRegionId = routeData.routeSegmentList[0].startNode.regionId;
      let deviceList = routeData.routeSegmentList;
      deviceList.forEach((item, index) => {
        let form = {
          label: "",
          image: "",
          number: "",
          categoryId: "",
          regionId: "",
        };
        if (tempRegionId !== item.startNode.regionId) {
          tempRegionId = item.startNode.regionId;
          categoryId++;
        }
        form.image = this.devicePictrue(item.endNode.nodeCategory);
        form.label = item.endNode.nodeName;
        form.number = item.channelsNum;
        form.categoryId = categoryId;
        form.regionId = item.endNode.regionId;
        formList.push(form);
        if (index == deviceList.length - 1) {
          //最后一个元素取end节点
          let form = {
            label: "",
            image: "",
            number: "",
            categoryId: "",
            regionId: "",
          };
          if (tempRegionId != item.endNode.regionId) {
            tempRegionId = item.endNode.regionId;
            categoryId++;
          }
          form.image = this.devicePictrue(item.endNode.nodeCategory);
          form.label = item.endNode.nodeName;
          form.number = item.channelsNum;
          form.categoryId = categoryId;
          form.regionId = item.endNode.regionId;
          formList.push(form);
          console.log("formList", formList);
          for (let i = 0; i <= categoryId; i++) {
            let lastForm = {
              label: "",
              subData: [],
            };
            this.dataList.push(lastForm);
          }

          this.createdData(formList, categoryId);
        }
      });
    },
    //详情----组装图像化的数据
    createdData(formList, categoryId) {
      formList.forEach((item) => {
        if (item.categoryId == 0) {
          this.dataList[item.categoryId].label =
            `A端：` + item.regionId;
        } else if (item.categoryId == categoryId) {
          this.dataList[item.categoryId].label =
            `Z端：` + item.regionId;
        } else {
          this.dataList[item.categoryId].label =
            `中间节点：` + item.regionId;
        }
        this.dataList[item.categoryId].subData.push(item);
      });
    },
    devicePictrue(DeviceCategory) {
      let image = "";
      if (DeviceCategory == this.nodeCategory.AFS) {
        image = require("@/assets/img/device/1.50.png");
      } else if (DeviceCategory == this.nodeCategory.ODF) {
        image = require("@/assets/img/device/1.53.png");
      } else if (DeviceCategory == this.nodeCategory.LightSplit) {
        image = require("@/assets/img/device/1.59.png");
      } else if (DeviceCategory == this.nodeCategory.Transport) {
        image = require("@/assets/img/device/1.47.png");
      } else if (DeviceCategory == this.nodeCategory.digitComm) {
        image = require("@/assets/img/device/1.47.png");
      } else if (DeviceCategory == this.nodeCategory.afsCluster) {
        image = require("@/assets/img/device/jiqun.png");
      }
      return image;
    },
  },
  mounted() {
    console.log(routeData);
    this.categoryByRegionId();
  },
};
</script>
